package com.start.common.tools;

import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StartUserTools {

    public static Map<String, List<String>> getUserKeyMap(Collection<String> startUserKeys) {

        return getUserKeyMap(startUserKeys, ":");
    }

    public static Map<String, List<String>> getUserKeyMap(Collection<String> startUserKeys, String split) {
        if (startUserKeys == null || startUserKeys.isEmpty()) {
            return new HashMap<>();
        }
        if (StringUtils.isAllBlank(split)) {
            split = ":";
        }
        String finalSplit = split;
        return startUserKeys.stream().filter(e -> StringUtils.isNotBlank(e) && e.contains(finalSplit)).collect(Collectors.groupingBy(e -> e.split(finalSplit)[1], Collectors.mapping(e -> e.split(finalSplit)[1], Collectors.toList())));
    }

    public static String getStartUserKey(String startUserType, String userId) {
        return startUserType + ":" + userId;
    }
}
